<template>
  <div>
    <Modal :value="showModal" :title="handleType" @on-visible-change="changeVisible">
      <Form ref="form" :model="formData" :rules="ruleCustom" :label-width="70">
        <FormItem style="display: none" v-if="formData.id">
          <label>
            <Input v-model="formData.id" :value="formData.id"/>
          </label>
        </FormItem>
        <FormItem label="名称" prop="name">
          <label>
            <Input v-model="formData.name" clearable placeholder="请填写环境名称"/>
          </label>
        </FormItem>
        <FormItem label="别名" prop="alias">
          <label>
            <Input v-model="formData.alias" clearable placeholder="请填写环境别名"/>
          </label>
        </FormItem>
        <Button
          long
          type="primary"
          size="large"
          @click="handleSubmit('form')">确认
        </Button>
      </Form>
      <div slot="footer"/>
    </Modal>
  </div>
</template>

<script>

  export default {
    name: 'AddEnvironment',
    props: {
      showModal: {
        type: Boolean,
        default: false
      },
      handleType: {
        type: String,
        default: '编辑部门'
      },
      usersData: {
        type: Array,
        default() {
          return []
        }
      },
      formData: {
        type: Object,
        default() {
          return {}
        }
      }
    },
    mounted() {
    },
    data() {
      return {
        loading: true,
        ruleCustom: {
          name: [
            {required: true, message: '名称必填', trigger: 'blur'}
          ],
        }
      }
    },
    methods: {
      handleSubmit(name) {
        this.$refs[name].validate((valid) => {
          if (valid) {
            this.$emit('handleSubmit', this.formData)
          } else {
            return false
          }
        })
      },
      changeVisible: function (val) {
        this.$refs['form'].resetFields()
        this.$emit('changeVisible', val)
      },
    }
  }
</script>

<style scoped>

</style>
